/**
 * 识别图片
 * @param {验证码类型} codetype 
 * @param {用户名} username 
 * @param {密码} password 
 * @param {软件id} soft_id 
 * @param {图片} img 
 * @returns 识别结果
 */
function PostPic(codetype, username, password, soft_id, img) {
    var headers = {
        'Connection': 'Keep-Alive',
        'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
    }

    img_base64 = images.toBase64(img)
    img.recycle();// 回收图片，注意 caputerScreen()返回的图片不需要回收，可把此行注释掉。

    var datas = {
        'codetype': codetype,
        'user': username,
        'pass': password,
        'softid': soft_id,
        'file_base64': img_base64
    }
    r = http.post('http://upload.chaojiying.net/Upload/Processing.php', data = datas, headers = headers)

    return r.body.json()
}
/**
 * 报错返分
 * @param {用户名} username 
 * @param {密码} password 
 * @param {软件id} soft_id 
 * @param {报错题目的图片ID} pic_id 
 * @returns 报错后返回结果
 */
function ReportError(username, password, soft_id, pic_id) {
    var headers = {
        'Connection': 'Keep-Alive',
        'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
    }
    var datas = {
        'id': pic_id,//报错题目的图片ID
        'user': username,
        'pass': password,
        'softid': soft_id,
    }
    r = http.post('http://upload.chaojiying.net/Upload/ReportError.php', data = datas, headers = headers)
    return r.body.json()
}
/**
 * 查询用户点数
 * @param {用户名} username 
 * @param {密码} password 
 * @returns 
 */
function GetScore(username, password){
    var datas = {
        'user': username,
        'pass': password,
    }
    r = http.post('http://upload.chaojiying.net/Upload/GetScore.php', data = datas)
    return r.body.json()
}


var username = '用户名'
var password = '密码'
var soft_id = '软件ID'
var codetype = 1902//验证码类型
var img = images.read("a.jpg");//读取图片要确保路径正确

res = PostPic(codetype, username, password, soft_id, img)
console.log("返回结果:", res)
console.log("返回代码:", res.err_no)
console.log("返回信息:", res.err_str)
console.log("图片标识号:", res.pic_id)
console.log("识别出的结果:", res.pic_str)
console.log("md5校验值:", res.md5)


res = GetScore(username, password)
console.log("返回结果:", res)
console.log("返回代码:", res.err_no)
console.log("返回信息:", res.err_str)
console.log("题分:", res.tifen)
console.log("锁定题分:", res.tifen_lock)
